<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>参数测试</title>
</head>
<body>
    <h1>参数测试页面</h1>
    
    <h2>测试预订</h2>
    <button onclick="testBooking()">测试预订请求</button>
    
    <h2>测试确认</h2>
    <button onclick="testConfirm()">测试确认请求</button>
    
    <h2>测试取消</h2>
    <button onclick="testCancel()">测试取消请求</button>
    
    <script>
    function getContextPath() {
        const path = window.location.pathname;
        const contextPath = path.substring(0, path.indexOf('/', 1));
        return contextPath || '';
    }
    
    function testBooking() {
        const contextPath = getContextPath();
        const params = new URLSearchParams();
        params.append('roomId', '1');
        params.append('customerName', '测试用户');
        params.append('customerPhone', '13800138000');
        params.append('customerEmail', 'test@test.com');
        params.append('checkInDate', '2025-06-20');
        params.append('checkOutDate', '2025-06-22');
        params.append('totalAmount', '576.00');
        
        fetch(contextPath + '/hotel/book', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: params
        })
        .then(response => response.json())
        .then(data => {
            console.log('预订结果:', data);
            alert('预订结果: ' + JSON.stringify(data));
        })
        .catch(error => {
            console.error('错误:', error);
            alert('错误: ' + error.message);
        });
    }
    
    function testConfirm() {
        const contextPath = getContextPath();
        const params = new URLSearchParams();
        params.append('bookingId', '1');
        
        fetch(contextPath + '/hotel/confirm', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: params
        })
        .then(response => response.json())
        .then(data => {
            console.log('确认结果:', data);
            alert('确认结果: ' + JSON.stringify(data));
        })
        .catch(error => {
            console.error('错误:', error);
            alert('错误: ' + error.message);
        });
    }
    
    function testCancel() {
        const contextPath = getContextPath();
        const params = new URLSearchParams();
        params.append('bookingId', '1');
        params.append('roomId', '1');
        
        fetch(contextPath + '/hotel/cancel', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: params
        })
        .then(response => response.json())
        .then(data => {
            console.log('取消结果:', data);
            alert('取消结果: ' + JSON.stringify(data));
        })
        .catch(error => {
            console.error('错误:', error);
            alert('错误: ' + error.message);
        });
    }
    </script>
</body>
</html>
